{include file='public/meta' }
  <title>友链添加 - 木鱼内容管理系统</title>
</head>
<body>

  <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">友链名称：</label>
      <div class="layui-input-block">
        <input type="text" id="urltitle" name="title" lay-verify="required|nlength" placeholder="请输入名称"  class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">链接URL：</label>
      <div class="layui-input-block">
      <div class="layui-input-inline" style="width:45%;">
        <input type="text" id="linkurl" name="url" lay-verify="url" value="http://" placeholder="请输入链接"  class="layui-input">
      </div>
      <button type="button" onClick="urltdk()" class="layui-btn" style="float:left;">一键获取</button>
    </div>
    </div>
	<div class="layui-form-item">
      <label class="layui-form-label">友链ico：</label>
       <div class="layui-input-block">
          <input class="layui-upload-file" type="file" accept="images" name="file">
          <div class="layui-input-inline" style="float:left;width:45%;">
          <input class="layui-input" type="text" id="upico" name="ico">
          </div>
          <button type="button"  class="layui-btn" id="icoup" style="float:left;">本地上传</button>
          <div style="float:left;margin-left: 5px;">
            <img height="46px" width="46px" style="border-radius: 50%;" id="ico1">
          </div>
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">友链描述：</label>
      <div class="layui-input-block">
        <input type="text" id="urlinfo" name="intro" value=""  class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">联系邮箱：</label>
      <div class="layui-input-block">
        <input type="text" name="email" value="" lay-verify="email" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">是否显示：</label>
      <div class="layui-input-block">
      <input type="checkbox" id="status" checked="" value="1" name="status" lay-filter="statusof" lay-skin="switch" lay-text="显示|隐藏" title="是否显示">
    </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">显示排序：</label>
      <div class="layui-input-block" style="margin-left:0px;width:10%;float:left;">
        <input type="number" name="orders" lay-verify="number" value="{$linkorder}"  class="layui-input">
      </div>
      <span style="text-align:center;float:left;font-size:14px;font-family:fantasy;color:red;">Tips:值越小,展示越靠前!</span>
    </div>
    
	
    <div class="layui-form-item layui-hide">
      <button type="button" lay-submit lay-filter="muyu-ajax-submit" id="muyu-ajax-submit">提交</button>
    </div>
  </div>
<style type="text/css" media="all">
/*上传头像样式开始*/
.layui-upload-img{width: 92px; height: 92px; margin: 0 10px 10px 0;}
/*上传头像样式结束*/
</style>
  {include file='public/footer' }
  <script>
  layui.config({
    base: '__ADMINST__layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['form'], function(){
    var $ = layui.$
    ,form = layui.form ;
    
    form.verify({
		    nlength: function (value) {
		    	var i,sum; 
		    	sum=0; 
		    	for(i=0;i<value.length;i++){ 
			    	if ((value.charCodeAt(i)>=0) && (value.charCodeAt(i)<=255)) 
			    		sum=sum+1; 
			    	else 
			    		sum=sum+2; 
		    	} 
		        if (sum > 20) {
		            return '网站标题最多10个文字或20个字符';
		        }
		    }
		});
    form.on('switch(statusof)', function(data){
    var value = this.checked ? '1' : '0';
    $("#status").val(value);
  });
    
  })
		   /*
		   *本地图片上传的操作
		   */
		layui.use('upload', function(){
		  var upload = layui.upload;
		   
		  //执行上传图片，并获取图片信息
		  var uploadInst = upload.render({
		    elem: '#icoup' //绑定元素
		    ,url: "{:url('Base/imgupload')}" //改成您自己的上传接口
            ,data:{upurl:'/public/upload/linkpic'}
		    ,done: function(res){
		      //上传完毕回调
			  // console.log(res);
			  if(res.code == 1){
				  $("#upico").val(res.photo);
				  $("#ico1").attr("src",res.photo);
				  layer.msg(res.msg,{time:2000});
			  }else{
				  layer.msg(res.msg,{time:2000});
			  }
		    }
		    ,error: function(){
		      //请求异常回调
		    }
		  });
		});
		
		function urltdk(){
		    var urls = $("#linkurl").val();
		    if(isUrl(urls)){
		    $.ajax({
	        type:"POST",
			data:{urls:urls},
			url:"{:url('admin/Plug/gettdk')}",
			dataType :"json",
			beforeSend: function() {
			    index = layer.load();
            },
			success:function(data){      
				if(data.code == 1){
				    $("#urltitle").val(data.msg['title']['content']);
				    $("#urlinfo").val(data.msg['description']['content']);
				    layer.msg("获取成功",{time:2000});
				}else{
				   layer.msg(data.msg,{time:2000}); 
				}
			},
			complete:function(){
			    layer.close(index);
            }
	    });
		  }else{
		  layer.msg("请输入正确的url!",{icon:2,time:2000});
		  }
		}
  </script>
</body>
</html>